<template>
	<view>
		<cu-custom :isBack="true" bgColor="bg-blue">
			<block slot="content">粗轧区域监控</block>
			<template slot="backText">
				<text class="cuIcon-back" @tap="beforePage"></text>
			</template>
		</cu-custom>
		<!-- 主题内容 -->
		<view  class="padding-t">
			<view class="public-main-info">
				<view class="u-main padding2030">
					<!-- 粗轧模型 -->
					<view class="mo-main">
						<image src="../../../static/img/rollCu.png" mode="widthFix" class="rollCu"></image>
						<view class="flex justify-center cu-zhuangtai width100">
							<view class="flex" style="margin-right: 30upx;">
								<view class="">
									<text class="ph-zhuangtai text-blue"></text>
								</view>
								<view class="font-size24 margin-left-10">
									<view class="u-font-weight">{{coilInfo.RmFault}}</view>
									<view class="u-font-weight6">状态</view>
								</view>
							</view>
							<view class="flex" style="margin-left: 30upx;">
								<view class="">
									<text class="ph-wendu text-blue"></text>
								</view>
								<view class="font-size24 margin-left-10">
									<view class="u-font-weight">{{coilInfo.temp}}℃</view>
									<view class="u-font-weight6">RDT</view>
								</view>
							</view>
						</view>
					</view>
					<!-- 钢卷信息 -->
					<view class="steel-coil-info dashed-bottom">
						<view class="u-font-weight font-size28 margin-b-10">钢卷信息</view>
						<view class="flex  font-size24 justify-between">
							<view>
								<text class="u-font-weight6">钢种</text>
								<text class="u-font-weight margin-left-10">{{coilInfo.steelGrade}}</text>
							</view>
							<view>
								<text class="u-font-weight6">钢卷号</text>
								<text class="u-font-weight margin-left-10">{{coilInfo.coilNo}}</text>
							</view>
							<view>
								<text class="u-font-weight6">规格</text>
								<text class="u-font-weight margin-left-10">{{coilInfo.CoilThk}}*{{coilInfo.CoilWid}}</text>
							</view>
						</view>
					</view>
					<!-- 轧机信息 -->
					<view class="roll-info">
						<view class="u-font-weight font-size28 margin-b-10">轧机信息</view>
						<view class="u-table">
							<view class="">
								<view class="u-table-head">
									<view class="u-table-head-item1">速度</view>
									<view class="u-table-head-item1">辊缝</view>
									<view class="u-table-head-item1">轧制力</view>
									<view class="u-table-head-item1">电流</view>
								</view>
								<view class="u-table-bady">
									<view class="u-table-bady-column">
										<view class="u-table-head-item1">{{rollInfo.speed}}</view>
										<view class="u-table-head-item1">{{rollInfo.gap}}</view>
										<view class="u-table-head-item1">{{rollInfo.force}}</view>
										<view class="u-table-head-item1">{{rollInfo.current}}</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="cu-tabbar-height"></view>
	</view>
</template>

<script>
	import { post } from "@/lib/Util.js";
	export default {
		data() {
			return {
				coilInfo: {
					coilNo: '---',
					steelGrade: '---',
					CoilThk: '---',
					CoilWid: '---',
					RmFault: '---',
					temp: '---'
				},
				rollInfo: {
					speed: 0,
					gap: 0,
					force: 0,
					current: 0
				},
				timer: null
			}
		},
		mounted() {
			this.getInfo()
			this.timer = setInterval(()=>{
				this.getInfo()
			},1000)
		},
		beforeDestroy() {
			clearInterval(this.timer)
			this.timer = null
		},
		methods: {
			beforePage() {
				uni.navigateBack({
					delta: 1
				});
			},
			async getInfo() {
				let coilNo = await post('/webservice/getHmiData', {
					tags: [
					    {
					      name: "RM_SCAN.CoilNo", // 钢卷号
					      ts: "1"
					    }
					  ]
				})
				let steelGrade = await post('/webservice/getHmiData', {
					tags: [
						{
						  name: "RM_SET.SteelGrade", // 钢种
						  ts: "1"
						}
					  ]
				})
				let CoilThk = await post('/webservice/getHmiData', {
					tags: [
						{
						  name: "RM_SET.CoilThk", // 成品厚
						  ts: "1"
						},
					  ]
				})
				let CoilWid = await post('/webservice/getHmiData', {
					tags: [
						{
						  name: "RM_SET.CoilWid", // 成品宽
						  ts: "1"
						}
					  ]
				})
				let RmFault = await post('/webservice/getHmiData', {
					tags: [
					    {
					      name: "RM_SCAN.RM_Fault", // 是否异常
					      ts: "1"
					    }
					  ]
				})
				let temp = await post('/webservice/getHmiData', {
					tags: [
					    {
					      name: "RM_SCAN.R1ExitTemp", // 温度
					      ts: "1"
					    }
					  ]
				})
				if (coilNo.code == 0) {
					this.coilInfo.coilNo = coilNo.data.tagList[0].value
				}
				if (steelGrade.code == 0) {
					this.coilInfo.steelGrade = steelGrade.data.tagList[0].value
				}
				if (CoilThk.code == 0) {
					this.coilInfo.CoilThk = Number(CoilThk.data.tagList[0].value).toFixed(2)
				}
				if (CoilWid.code == 0) {
					this.coilInfo.CoilWid = Number(CoilWid.data.tagList[0].value).toFixed(2)
				}
				if(RmFault.code == 0) {
					if(RmFault.data.tagList[0].value == 1) {
						this.coilInfo.RmFault = '故障'
					}else {
						this.coilInfo.RmFault = '在轧'
					}
					
				}
				if(temp.code == 0) {
					this.coilInfo.temp = temp.data.tagList[0].value
				}
				
				let R1GapDS = await post('/webservice/getHmiData', {
					tags: [
					    {
					      name: "RM_SCAN.R1GapDS", // ds辊缝
					      ts: "1"
					    }
					  ]
				})
				let R1Gapos = await post('/webservice/getHmiData', {
					tags: [
					    {
					      name: "RM_SCAN.R1GapOS", // os辊缝
					      ts: "1"
					    }
					  ]
				})
				let gapds = R1GapDS.data.tagList[0].value
				let gapos = R1Gapos.data.tagList[0].value
				let gap = 0
				if(gapds && gapos) {
					gap = Number((Number(gapds) + Number(gapos)) / 2).toFixed(2)
				}
				let R1Speed = await post('/webservice/getHmiData', {
					tags: [
					    {
					      name: "RM_SCAN.R1Speed", // 轧制速度
					      ts: "1"
					    }
					  ]
				})
				let R1Current = await post('/webservice/getHmiData', {
					tags: [
					    {
					      name: "RM_SCAN.R1Current", // 主电机电流
					      ts: "1"
					    }
					  ]
				})
				let R1ForceDS = await post('/webservice/getHmiData', {
					tags: [
					    {
					      name: "RM_SCAN.R1ForceDS", // R1轧制力(DS侧)
					      ts: "1"
					    }
					  ]
				})
				let R1ForceOS = await post('/webservice/getHmiData', {
					tags: [
					    {
					      name: "RM_SCAN.R1ForceOS", // R1轧制力(OS侧)
					      ts: "1"
					    }
					  ]
				})
				let force = 0
				let forceDs = R1ForceDS.data.tagList[0].value
				let forceOS = R1ForceOS.data.tagList[0].value
				if(forceDs && forceOS) {
					force = Number((Number(forceDs) + Number(forceOS))).toFixed(2)
				}
				this.rollInfo.current = R1Current.data.tagList[0].value
				this.rollInfo.speed = R1Speed.data.tagList[0].value
				this.rollInfo.gap = gap
				this.rollInfo.force = force
			}
		}
	}
</script>

<style>
	.mo-main {
		width: 100%;
		height: 425upx;
		opacity: 1;
		background: #f5f5f5;
		border-radius: 6upx;
		position: relative;
	}
	.steel-coil-info {
		padding: 30upx 0 20upx 0;
	}
	.roll-info {
		padding-top: 20upx;
	}
	.rollCu {
		position: absolute;
		top: 89upx;
		left: 50%;
		transform: translateX(-50%);
	}
	.cu-zhuangtai {
		bottom: 34upx;
		position: absolute;
		font-size: 60upx;
	}
</style>

